package com.luping.xiao.xiao.controller;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.LineIterator;

import java.io.*;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class TestJava {

    public static void main(String[] str) {
        System.out.println(strToDate("2019-08-25 14:39", "yyyy-MM-dd HH:mm").getTime());
        System.out.println(strToDate("2019-08-25 14:39", "yyyy-MM-dd HH:mm"));
    }
    public static Date strToDate(String dateStr, String format) {
        if ((dateStr == null) || dateStr.equals("")) {
            return null;
        }

        Date date = null;
        DateFormat df = new SimpleDateFormat(format);
        try {
            date = df.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    public static void readWriteFile(String inPath, String outPath, String encoding) {
        BufferedWriter out = null;
        LineIterator it = null;
        FileWriter fw = null;
        try {
            it = FileUtils.lineIterator(new File(inPath));
            File f = new File(outPath);
            if (!f.exists()) {
                f.createNewFile();
            }
            fw = new FileWriter(f);
            out = new BufferedWriter(fw);
            int i = 3791361;
            while (it.hasNext()) {
                i++;
                //解析行数据
                String rowData = it.nextLine();
                if (rowData != null && !"".equals(rowData) && rowData.indexOf("2019-07-04") == -1) {
                    String ids = rowData.substring(rowData.indexOf(" (") + 2, rowData.indexOf(", ''"));
                    out.write(rowData.replaceAll("2019-07-03", "2019-06-21").replace(ids, i + "") + "\r\n");
                    out.flush();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                out.flush();
                out.close();
                fw.close();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }

    }
}
